#!/bin/bash
source /etc/profile
#
##set color##
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }
##set color##
#
project="apitest"
echo -------------------------------------
echo $BUILD_NUMBER;
# cd Jenkins2Docker
git pull --rebase origin master;
docker stop apitest;
docker rm apitest;
docker build -t apitest:$BUILD_NUMBER .;
#docker images;
#docker run -p 10001:80 -p 5008:443 -d --name apitest apitest:$BUILD_NUMBER;
# -v ~/docker-data/house-web/appsettings.json:/app/appsettings.json -v ~/docker-data/house-web/NLogFile/:/app/NLogFile   --restart=always
#docker logs apitest;
#删除build过程中产生的镜像    #docker image prune -a -f
#docker rmi $(docker images -f "dangling=true" -q)

#更新镜像

echoGreen "开始部署最新镜像！" 
#rancher kubectl set image deployment/$project $project=$project:$BUILD_NUMBER -n apitest
rancher kubectl set image deployment/$project   $project=$project:$BUILD_NUMBER
[ $? != 0 ] && echoRed "请注意，在执行镜像更新时出错，故而退出！" && exit 1
echoGreen "部署完成！"